package com.feri.rbacsys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feri.rbacsys.dao.DepositoryDao;
import com.feri.rbacsys.entity.Buyorder;
import com.feri.rbacsys.mapper.BuyorderMapper;
import com.feri.rbacsys.mapper.ProductAmountMapper;
import com.feri.rbacsys.service.BuyorderService;
import com.feri.rbacsys.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 神经质的木子李
 * @description 针对表【t_buyorder】的数据库操作Service实现
 * @createDate 2023-03-28 15:31:29
 */
@Service
public class BuyorderServiceImpl extends ServiceImpl<BuyorderMapper, Buyorder>
        implements BuyorderService {
    @Resource
    private BuyorderMapper buyorderMapper;
    @Resource
    private DepositoryDao dao;
    @Resource
    private ProductAmountMapper productAmountMapper;

    @Override
    public R purchaseGoods(Buyorder buyorder) {
        if (buyorder != null) {
            if (buyorderMapper.insert(buyorder) > 0) {
//                ProductVo productVo = buyorderMapper.selByName(buyorder.getProductName());
//                int count = dao.selectCount(productVo.getId());
//                System.out.println("库存是：" + count);
//                count += buyorder.getBuyStock();
//                ProductAmount productAmount = new ProductAmount(productVo.getId(), count);
//                productAmountMapper.insert(productAmount);
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R selectAll() {
        return R.ok(buyorderMapper.getall());
    }
}




